package com.letv.so.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Formatter;
import java.util.Locale;

public final class NumberUtil {

	private static final String[] numArr = { "零", "一", "二", "三", "四", "五", "六",
			"七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六" };

	public static String getCapitalNumber(int num) {
		if (num >= 0 && num <= numArr.length) {
			return numArr[num];
		} else {
			return null;
		}
	}

	public static final int getInt(String numStr, int defaultNum, int maxNum) {
		if (numStr == null || numStr.trim().length() == 0) {
			return defaultNum;
		}
		try {
			int reNum = Integer.valueOf(numStr);
			return maxNum > 0 && reNum > maxNum ? maxNum : reNum;
		} catch (NumberFormatException e) {
			return defaultNum;
		}
	}
	
	public static final int getInt(String strNum, int defaultNum){
		return getInt(strNum, defaultNum, 0);
	}
	
	public static final long getLong(String numStr, long defaultNum) {
		if (numStr == null || numStr.trim().length() == 0) {
			return defaultNum;
		}
		try {
			return Long.valueOf(numStr).longValue();
		} catch (NumberFormatException e) {
			return defaultNum;
		}
	}
	
	public static final float getFloat(String numStr, float defaultNum) {
		if (numStr == null || numStr.trim().length() == 0) {
			return defaultNum;
		}
		try {
			return Float.valueOf(numStr).floatValue();
		} catch (NumberFormatException e) {
			return defaultNum;
		}
	}

	@SuppressWarnings("unused")
	private static String getYear(long millis) {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(millis);
		SimpleDateFormat time = new SimpleDateFormat("yyyy");
		time.format(cal);
		Formatter ft = new Formatter(Locale.CHINA);
		return ft.format("yyyy", cal).toString();
	}
	public static void main(String[] args){
		System.out.println(getInt("2147483647", 0));
	}
}
